package jpal.base;

import static org.junit.Assert.assertTrue;
import jpal.base.MoreStrings;

import org.junit.Test;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;

public class MoreStringsTest {

	@Test
	public void endsWithIgnoreCase() {
		final String string = "The Quick Brown Fox Jumps Over The Lazy Dog";
		final String suffix = "the lazy dog";
		assertTrue(string.toLowerCase().endsWith(suffix));
		assertTrue(MoreStrings.endsWithIgnoreCase(string, suffix));
	}

	@Test
	public void startsWithIgnoreCase() {
		final String string = "The Quick Brown Fox Jumps Over The Lazy Dog";
		final String prefix = "the quick brown";
		assertTrue(string.toLowerCase().startsWith(prefix));
		assertTrue(MoreStrings.startsWithIgnoreCase(string, prefix));
	}

	@Test
	public void startsWithIgnoreCaseOffset() {
		final String string = "The Quick Brown Fox Jumps Over The Lazy Dog";
		final String prefix = "quick brown";
		assertTrue(string.toLowerCase().startsWith(prefix, 4));
		assertTrue(MoreStrings.startsWithIgnoreCase(string, prefix, 4));
	}

	@Test
	public void readLines() {
		final String string = "line1\nline2\nline3\nline4";
		final Iterable<String> lines = MoreStrings.readLines(string);
		final Iterable<String> list = ImmutableList.of("line1", "line2",
				"line3", "line4");
		assertTrue(Iterables.elementsEqual(lines, list));
	}

}